package blazingbubble.graphics.game;

import blazingbubble.config.Config;
import blazingbubble.game.*;
import blazingbubble.game.Game;
import blazingbubble.game.command.GameCommandFactory;
import blazingbubble.graphics.IActivable;
import blazingbubble.exception.StartupException;

import javax.media.opengl.GLCanvas;
import javax.swing.*;
import java.awt.*;

public class InGame implements IActivable {
	private GLCanvas canvas;

	private Container displayArea;
	private Scene scene;
	private Game game;
	private Integer frameBreak;

	public InGame(Container displayArea, GameCommandFactory commandFactory, Game game, Integer frameBreak) {
		this.displayArea = displayArea;
		this.game = game;
		this.frameBreak = frameBreak;
		canvas = (GLCanvas)displayArea.getComponent(0);
		scene = new Scene(game, commandFactory, frameBreak);
		canvas.addGLEventListener(scene);
		canvas.addKeyListener(scene);
		canvas.addMouseMotionListener(scene);
	}

	@Override
	public void activate() {
		displayArea.removeAll();
		displayArea.add(canvas);
		((JPanel)displayArea).updateUI();
	}

	public void startup(Config config) {
		scene.setConfig(config);
	}
	
	public void setGameCommandFactory(GameCommandFactory gameCommandFactory){
		this.scene = new Scene(game, gameCommandFactory, frameBreak);
	}
}
